---
title: "Cell Components"
description: "Component cell renderers allow images, buttons, and hyperlinks to be added to $framework Table Cells. Use a provided cell renderer or create a custom cell renderer."
---

{% if isFramework("javascript") %}
Custom HTML / DOM inside Cells is achieved using Cell Components.
Create Custom Cell Components to have any HTML markup
in a cell. The grid comes with some Provided Cell Components for common grid tasks.
{% /if %}

{% if isFramework("vue") %}
Custom HTML / DOM inside Cells is achieved using Cell Components.
Create Custom Cell Components to have any HTML markup
in a cell. The grid comes with some Provided Cell Components for common grid tasks.
{% /if %}

{% if isFramework("react") %}
{% videoSection id="9IbhW4z--mg" title="React Cell Renderers" showHeader=true %}
Custom HTML / DOM inside Cells is achieved using Cell Components.
Create Custom Cell Components to have any HTML markup
in a cell. The grid comes with some Provided Cell Components for common grid tasks.
{% /videoSection %}
{% /if %}

{% if isFramework("angular") %}
{% videoSection id="xsafnM77NVs" title="Angular Cell Renderers" showHeader=true %}
Custom HTML / DOM inside Cells is achieved using Cell Components.
Create Custom Cell Components to have any HTML markup
in a cell. The grid comes with some Provided Cell Components for common grid tasks.
{% /videoSection %}
{% /if %}

The example below shows adding images, hyperlinks, and buttons to a cell using Custom Cell Components. The custom button logs to the developer console when clicked.

{% gridExampleRunner title="Simple Cell Renderer" name="cell-renderer-summary"  exampleHeight=460 /%}

## Provided Components

The grid comes with some built in Cell Components that cover some common cell rendering requirements.

* [Group Cell Component](./grouping-single-group-column/#cell-component): For showing group details with expand and collapse functionality when using any of [Row Grouping](./grouping/), [Master Detail](./master-detail/) or [Tree Data](./tree-data/).

* [Animate Change Cell Renderers](./change-cell-renderers/#animated-cell-renderers): For animating changes when data is updated.

* [Checkbox Cell Renderer](./cell-data-types/#boolean): For displaying boolean values with a checkbox when `cellDataType` of Boolean is used.

## Custom Components

{% if isFramework("angular") %}
{% metaTag tags=["ICellRendererAngularComp"] /%}
{% /if %}

{% partial file="./_component-interface-angular.mdoc" /%}
{% partial file="./_component-interface-javascript.mdoc" /%}
{% partial file="./_component-interface-react.mdoc" /%}
{% partial file="./_component-interface-vue.mdoc" /%}

{% if isFramework("javascript", "angular", "vue") %}
{% interfaceDocumentation interfaceName="ICellRendererParams" /%}
{% /if %}

{% if isFramework("react") %}
{% interfaceDocumentation interfaceName="CustomCellRendererProps" /%}
{% /if %}

{% note %}
Note that if [Row Selection](./row-selection/) is enabled, it is recommended to set `suppressKeyboardEvent` on the column definition to prevent the {% kbd "␣ Space" /%} key from triggering both row selection and toggling the checkbox.
{% /note %}

{% partial file="./_renderer-function-javascript.mdoc" /%}
{% partial file="./_renderer-function-angular.mdoc" /%}
{% partial file="./_renderer-function-vue.mdoc" /%}

### Selecting Components

The Cell Component for a Column is set via `colDef.cellRenderer` and can be any of the following types:

{% if isFramework("javascript") %}
1. `String`: The name of a registered Cell Component, see [Registering Custom Components](./components/#registering-custom-components)
1. `Class`: Direct reference to a Cell Component.
1. `Function`: A function that returns either an HTML string or DOM element for display.
{% /if %}

{% if isFramework("angular") %}
1. `String`: The name of a registered Cell Component, see [Registering Custom Components](./components/#registering-custom-components)
1. `Class`: Direct reference to a Cell Component.
1. `Function`: A function that returns either an HTML string or DOM element for display.
{% /if %}

{% if isFramework("vue") %}
1. `String`: The name of a registered Cell Component, see [Registering Custom Components](./components/#registering-custom-components)
1. `Function`: A function that returns either an HTML string or DOM element for display.
{% /if %}

{% if isFramework("react") %}
1. `String`: The name of a registered Cell Component, see [Registering Custom Components](./components/#registering-custom-components)
1. `Component`: Direct reference to a Cell Component.
1. `Inlined Component`: An inlined Cell Component.
{% /if %}

The code snippet below demonstrates each of these method types.

{% if isFramework("javascript", "angular") %}
```{% frameworkTransform=true spaceBetweenProperties=true %}
const gridOptions = {
    columnDefs: [
        // 1 - String - The name of a Cell Component registered with the grid.
        {
            field: 'age',
            cellRenderer: 'agGroupCellRenderer',
        },
        // 2 - Class - Provide your own Cell Component directly without registering.
        {
            field: 'sport',
            cellRenderer: MyCustomCellRendererClass,
        },
        // 3 - Function - A function that returns an HTML string or DOM element for display
        {
            field: 'year',
            cellRenderer: params => {
                // put the value in bold
                return 'Value is <b>' + params.value + '</b>';
            }
        }
    ]
}
```
{% /if %}

{% if isFramework("react") %}
```{% spaceBetweenProperties=true %}
const [columnDefs] = useState([
    // 1 - String - The name of a Cell Component registered with the grid.
    {
        field: 'age',
        cellRenderer: 'agGroupCellRenderer',
    },
    // 2 - Component - Provide your own Cell Component directly without registering.
    {
        field: 'sport',
        cellRenderer: MyCustomCellRendererClass,
    },
    // 3 - Inlined Component
    {
        field: 'year',
        cellRenderer: props => {
            // put the value in bold
            return <>Value is <b>{props.value}</b></>;
        }
    }
]);
```
{% /if %}

{% if isFramework("vue") %}
```{% frameworkTransform=true spaceBetweenProperties=true %}
const gridOptions = {
    columnDefs: [
        // 1 - String - The name of a Cell Component registered with the grid.
        {
            field: 'age',
            cellRenderer: 'agGroupCellRenderer',
        },
        // 2 - Function - A function that returns an HTML string or DOM element for display
        {
            field: 'year',
            cellRenderer: params => {
                // put the value in bold
                return 'Value is <b>' + params.value + '</b>';
            }
        }
    ]
}
```
{% /if %}

### Dynamic Component Selection

The `colDef.cellRendererSelector` function allows setting different Cell Components for different Rows within a Column.

The `params` passed to `cellRendererSelector` are the same as those passed to the [Cell Renderer Component](./component-cell-renderer/). Typically the selector will use this to check the row's contents and choose a renderer accordingly.

The result is an object with `component` and `params` to use instead of `cellRenderer` and `cellRendererParams`.

This following shows the selector choosing between Mood and Gender Cell Renderers based on the row data.


{% partial file="./_selector-common.mdoc" /%}
{% partial file="./_selector-vue.mdoc" /%}


The example below demonstrates the use of `cellRendererSelector` to dynamically select a Cell Component based on the row data.

* The column 'Value' holds data of different types as shown in the column 'Type' (numbers/genders/moods).
* `colDef.cellRendererSelector` is a function that selects the renderer based on the row data.
* The column 'Rendered Value' show the data rendered applying the component and params specified by `colDef.cellRendererSelector`

{% gridExampleRunner title="Dynamic Rendering Component" name="dynamic-rendering-component"  exampleHeight=335 /%}

### Accessing Instances

After the grid has created an instance of a Cell Component for a cell it is possible to access that instance. This is useful if you want to call a method that you provide on the Cell Component that has nothing to do with the operation of the grid. Accessing Cell Components is done using the grid API `getCellRendererInstances(params)`.

{% apiDocumentation source="grid-api/api.json" section="rendering" names=["getCellRendererInstances"] /%}

An example of getting the Cell Component for exactly one cell is as follows:

```js
// example - get cell renderer for first row and column 'gold'
const firstRowNode = api.getDisplayedRowAtIndex(0);
const params = { columns: ['gold'], rowNodes: [firstRowNode] };
const instances = api.getCellRendererInstances(params);

if (instances.length > 0) {
    // got it, user must be scrolled so that it exists
    const instance = instances[0];
}
```

Note that this method will only return instances of the Cell Component that exists. Due to Row and Column Virtualisation, Cell Components will only exist for Cells that are within the viewport of the Vertical and Horizontal scrolls.

The example below demonstrates custom methods on Cell Components called by the application. The following can be noted:

* The medal columns are all using the user defined `MedalCellRenderer`. The Cell Component has an arbitrary method `medalUserFunction()` which prints some data to the developer console.
* The **Gold** button executes a method on all instances of the Cell Component in the gold column and prints the data to the developer console.
* The **First Row Gold** button executes a method on the gold cell of the first row only and prints data to the developer console. Note that the `getCellRendererInstances()` method will return nothing if the grid is scrolled far past the first row showing row virtualisation in action.
* The **All Cells** button executes a method on all instances of all Cell Components and prints data to the developer console.

{% gridExampleRunner title="Get Cell Renderer" name="get-cell-renderer" /%}

### Custom Props

The `props` passed to the Cell Component can be complemented with custom props. This allows configuring reusable Cell Components - e.g. a component could have buttons that are optionally displayed via additional props.

Complement props to a cell renderer using the Column Definition attribute  `cellRendererParams`. When provided, these props will be merged with the grid provided props.

{% partial file="./_complementing-component-javascript.mdoc" /%}
{% partial file="./_complementing-component-angular.mdoc" /%}
{% partial file="./_complementing-component-react.mdoc" /%}
{% partial file="./_complementing-component-vue.mdoc" /%}

This example shows rendering an image with and without custom props and using custom props to pass a callback to a button.
The `Refresh Data` button triggers the cell components to refresh by randomising the success data. The `Launch` button logs a message to the developer console.

{% gridExampleRunner title="Custom Props" name="custom-props" /%}

{% if isFramework("javascript") %}
{% note %}
You might be wondering how the grid knows if you have provided a Cell Renderer component class or
a simple function, as JavaScript uses functions to implement classes. The answer is the grid looks
for the `getGui()` method in the prototype of the function (a mandatory method in the cell renderer
interface). If the `getGui()` method exists, it assumes a component, otherwise it assumes a function.
{% /note %}
{% /if %}

### Dynamic Tooltips

When working with Custom Cell Renderers it is possible to register custom tooltips that are displayed dynamically by using the `setTooltip` method.
{% if isFramework("javascript", "angular", "vue") %}
{% interfaceDocumentation interfaceName="ICellRendererParams" names=["setTooltip"] /%}
{% /if %}

{% if isFramework("react") %}
{% interfaceDocumentation interfaceName="CustomCellRendererProps" names=["setTooltip"] /%}
{% /if %}

The example below demonstrates a dynamic tooltip being displayed on Cell Components. The following can be noted:

* The Athlete column uses the `shouldDisplayTooltip` callback to only display Tooltips when the text is not fully displayed.

{% gridExampleRunner title="Dynamic Tooltips" name="dynamic-tooltips" /%}

### Defer Slow Cell Components

If a Custom Cell Component is slow to render, the grid may appear unresponsive due to the custom component blocking the main thread. This can be avoided by deferring the rending of slow components as follows:

```js
{
    cellRenderer: 'SlowCellRenderer',
    cellRendererParams: {
        deferRender: true
    }
}
```

Deferred components will be rendered after other cells and only after the grid has stopped scrolling. In the meantime, the loading cell renderer will be displayed. If [Row Grouping](./grouping) is active only custom cells in leaf nodes will be deferred. 

The example below demonstrates the use of `deferRender` to defer the rendering of an artificially slow cell component. The following can be noted when scrolling:

* The column 'Slow Renderer' is deferred and shows the default skeleton cell loader.
* The column 'Slow Renderer Custom' is deferred but uses a custom loading cell defined via `colDef.loadingCellRenderer`.
* The column 'Fast Renderer' is a custom component but not deferred so renders immediately along with the other plain cells. 
* The `cellRendererSelector` only returns the Slow Cell Renderer for leaf nodes as an optimisation. 


{% gridExampleRunner title="Slow Cell Renderer" name="slow-cell-renderer" /%}

{% if isFramework("react") %}
{% note %}
`deferRender` uses `startTransition` to reduce the priority of deferred components. There is a known limitation in React that transitions are currently batched together meaning all deferred components appear at the same time. For more information, see the React documentation [StartTransition - Caveats](https://react.dev/reference/react/useTransition#starttransition-caveats).
{% /note %}

### Lazy Loading Cell Components

The grid supports lazy loading of Custom Cell Components by displaying the `loadingCellRenderer` until the custom cell has loaded. 

The example below uses [React.lazy](https://react.dev/reference/react/lazy) to load the cell component for the Lazy Loaded Renderer column with an artificial delay of 3 seconds.

{% gridExampleRunner title="Lazy Cell Renderer" name="lazy-renderer" /%}

{% /if %}

### Keyboard Navigation

When using custom Cell Components, the custom Cell Component is responsible for implementing support for keyboard navigation among its focusable elements. This is why by default, focusing a grid cell with a custom Cell Component will focus the entire cell instead of any of the elements inside the custom cell renderer.

In order to handle focus in your custom cell component, implement [Custom Cell Component Keyboard Navigation](./keyboard-navigation/#custom-cell-component).

### Handling Mouse Events

By default when a cell is clicked on, the grid will perform actions including:

- Focusing the cell.

- Updating the cell selection, if [Cell Selection](./cell-selection/) is enabled.

- Selecting the row, if [Row Selection](./row-selection/) is enabled.

- Starting editing, if [Editing](./cell-editing/) is enabled.

This behaviour may not be desirable for custom cell components, e.g. if they contain interactive elements. In this situation, the grid can be prevented from handling the mouse event (`'click'`, `'dblclick'`, `'mousedown'` or `'touchstart'`), by passing the `suppressMouseEventHandling` callback to `cellRendererParams`.

```{% frameworkTransform=true %}
const gridOptions = {
    columnDefs: [
        {
            colId: 'customButton',
            cellRenderer: CustomButtonComponent,
            cellRendererParams: {
                suppressMouseEventHandling: (params) => true,
            },
        },
    ],
}
```

{% interfaceDocumentation interfaceName="EventCellRendererParams" config={"description":""} /%}

Note that whilst the callback will prevent the grid from performing actions, it will still continue to fire events (e.g. `onCellClicked`). These events will have the `isEventHandlingSuppressed` property set to `true` if the callback returns `true`.

The following example demonstrates using `suppressMouseEventHandling` with cell selection, row selection, and editing. Mouse events are suppressed for the Button column.

{% gridExampleRunner title="Handling Mouse Events" name="handling-mouse-events" /%}

It is also possible to stop propagation on mouse events from within a custom cell component, but this must be done for each of the mouse events described above.

{% if isFramework("react") %}
To manually prevent the grid from handling mouse events, the "capture" versions of event handlers must be used, e.g. `onClickCapture` instead of `onClick`.
{% /if %}
